package jf.jufanzhibo.view.home.view;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.support.design.widget.TabLayout;

import jf.jufanzhibo.R;
import jf.jufanzhibo.view.home.IUserview;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment implements IUserview {
    private static HomeFragment homeFragment;
    public static final String ARGS_PAGE = "args_page";
    private int mPage;
    private ImageButton home_btnseclect;
    private ImageButton home_btnsetting;
    private TabLayout tableLayout;
    private ViewPager vp_findFragment_pager;

    public HomeFragment() {
        // Required empty public constructor
    }
    public Handler hander=new Handler(){
        @Override
        public void handleMessage(Message msg) {



        }
    };
    public static HomeFragment newInstance(int page) {
        Bundle args = new Bundle();
        args.putInt(ARGS_PAGE, page);
        HomeFragment fragment = new HomeFragment();
        //给每页传递不同数据
        fragment.setArguments(args);
        return fragment;
    }

    public static Fragment setFragment() {
        if (homeFragment == null)
            synchronized (HomeFragment.class) {
                if (homeFragment == null) {
                    homeFragment = new HomeFragment();
                }
            }
        return homeFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPage = getArguments().getInt(ARGS_PAGE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home,container,false);
        return view;

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    //初始化控件
    @Override
    public void initview() {
        home_btnseclect = (ImageButton) getView().findViewById(R.id.home_seclete);
        home_btnsetting = (ImageButton) getView().findViewById(R.id.home_setting);
        tableLayout = (TabLayout) getView().findViewById(R.id.tabLayout);
        vp_findFragment_pager = (ViewPager) getView().findViewById(R.id.vp_FindFragment_pager);

    }
    //设置监听
    @Override
    public void initselect() {
        tableLayout.setupWithViewPager(vp_findFragment_pager);

    }
    //加载解析数据
    @Override
    public void loadJson() {

    }
}
